﻿using System;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
namespace AnyOffice.general.system.dept
{
    public partial class delete : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["dept_id"] == null) ? 0 : int.Parse(Request.QueryString["dept_id"].ToString());
                DepartmentDao dao = new DepartmentDao();
                if (dao.IsExistsChild(base.Conn, num))
                {
                    this.lblMessage.Text = base.ShowPrompt("请先删除该部门/成员单位下的子部门/成员单位");
                }
                else if (!dao.Delete(base.Conn, num))
                {
                    this.lblMessage.Text = base.ShowPrompt("该部门/成员单位下存在用户，请首先删除该部门/成员单位下的用户");
                }
                else
                {
                    this.lblMessage.Text = base.ShowPrompt("部门/成员单位删除成功", "index.aspx");
                    string str = "DeptId=" + num.ToString();
                    SysLog.Log(base.Conn, 5, str);
                    this.lblMessage.Text = base.ShowPromptNoNav("部门/成员单位已删除");
                    StringBuilder builder = new StringBuilder("<script>\n");
                    builder.Append("parent.dept_list.location='dept_list.aspx';\n");
                    builder.Append("</script>\n");
                    if (!this.Page.IsClientScriptBlockRegistered("dept_list"))
                    {
                        this.Page.RegisterClientScriptBlock("dept_list", builder.ToString());
                    }
                }
            }

        }
    }
}
